//
//  AuctionManagerListCell.m
//  Ticket
//
//  Created by 小禹宝宝 on 2017/10/27.
//  Copyright © 2017年 cy55. All rights reserved.
//

#import "AuctionManagerListCell.h"
@interface AuctionManagerListCell ()
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UIView *topShadowView;
@property (weak, nonatomic) IBOutlet UIButton *soldOutBtn;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;

@end
@implementation AuctionManagerListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.topShadowView.backgroundColor = [BLColorConfig backgroundColor];
    self.headImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.headImageView.layer.masksToBounds = YES;
    self.soldOutBtn.layer.borderWidth = 1.0f;
    self.soldOutBtn.layer.borderColor = [[BLColorConfig defaultBlueColor] CGColor];
    [self.soldOutBtn setTitleColor:[BLColorConfig defaultBlueColor] forState:UIControlStateSelected];
    [self.soldOutBtn setTintColor:[UIColor whiteColor]];
    [self.soldOutBtn setTitleColor:[BLColorConfig defaultBlueColor] forState:UIControlStateNormal];
}

- (void)setModel:(TKGoodsItem *)model {
    _model = model;
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.headimg] placeholderImage:nil];
    self.titleLabel.text = model.title;
    self.priceLabel.text = model.price;
    self.soldOutBtn.selected = model.status;
    
}
- (IBAction)soldOutAction:(UIButton *)sender {
    
    NSString *str;
    if (sender.selected) {
        str = @"确定下架吗？";
    } else {
        str = @"确定上架吗？";
    }
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:str preferredStyle:UIAlertControllerStyleAlert];
    
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击取消");
    }]];
    
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        NSInteger status = !sender.selected;
        NSString *staStr = [NSString stringWithFormat:@"%ld",(long)status];
        NSDictionary *params = @{@"status":staStr,@"goods_id":self.model.id};
        [self ks_showProgress];
        @weakify(self)
        [BLApi POST:URL_Goods_manage parameters:params decodeClass:[BLBaseResponse class] completion:^(id responseObject, id responseDataOriginal, NSError *error) {
            @strongify(self)
            [self ks_hideProgress];
            BLBaseResponse *resp = (BLBaseResponse *)responseObject;
            if (resp.isSuccess) {
                sender.selected = status;
                //            if (self.statusBlock) {
                //                self.statusBlock(YES);
                //            }
            } else {
                [self ks_showToast:@"操作失败，请重试"];
            }
        }];
        
    }]];
    [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:alertController animated:YES completion:nil];
    

}
@end
